package gameoflife;

public class Position implements Comparable<Position> {

	protected int x, y;

	public Position() {
		this(0, 0);
	}

	public Position(int x, int y) {
		this.x = x;
		this.y = y;
	}

	public Position(Position position) {
		this(position.x, position.y);
	}

	public final int getX() {
		return x;
	}

	public final int getY() {
		return y;
	}

	public final void moveTo(int x, int y) {
		this.x = x;
		this.y = y;
	}

	@Override
	public boolean equals(Object o) {
		if (o instanceof Position) {
			return x == ((Position)o).x && y == ((Position)o).y;
		}
		return false;
	}

	@Override
	public int hashCode() {
		return x ^ (y << 14);
	}

	@Override
	public int compareTo(Position p) {
		if (this.y < p.y) {
			return -1;
		}
		if (this.y > p.y) {
			return 1;
		}
		if (this.x < p.x) {
			return -1;
		}
		if (this.x > p.x) {
			return 1;
		}
		return 0;
	}

	@Override
	public String toString() {
		return "(" + x + ", " + y + ")";
	}
}
